package com.mytransaction.service.impl;

import com.mytransaction.annotation.MyTransactional;
import com.mytransaction.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UserServiceImpl implements UserService {

    private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    @Override
    @MyTransactional // 加上事务注解
    public void saveUser(String name) throws Exception {
        logger.info("执行保存用户操作: {}", name);
        if ("error".equalsIgnoreCase(name)) {
            // 模拟一个运行时异常
            throw new RuntimeException("模拟数据库操作失败！");
        }
        logger.info("用户 [{}] 保存成功。", name);
    }

    @Override
    public String findUser(String name) {
        logger.info("执行查找用户操作: {}", name);
        return "Found user: " + name;
    }
}
